package com.sf.web.controller;

import com.sf.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@CrossOrigin
public class LoginController {

    /**
     *  /login
     *  参数: username 账号  password 密码
     *
     *  {success: true/false,msg: 登录成功/账号密码错误, data: username/null}
     */
    @RequestMapping("/login")
    @ResponseBody
    public JsonResult login(String username, String password, HttpSession session){
        // 判断账号是否为admin , 密码是否123
        if("admin".equals(username)&& "123".equals(password)){
            // 把用户名放到session 当中为了后续的登录拦截做铺垫
            session.setAttribute("USERNAME_IN_SESSION",username);
            return new JsonResult(true,"登录成功",username);
        }else{
            return new JsonResult(false,"账号密码错误",null);
        }
    }
}
